<template>
  <div class="app-container calendar-list-container">
    <el-form class="small-space" :model="reqData" label-position="right" label-width="90px" :inline="true">

      <!-- 头信息 -->
      <quote-head :reqData="reqData" @qllChange="getQLLVal"></quote-head>

      <!-- 明细 -->
      <quote-detail :quoteId="reqData.quote_head.quote_id" :quoteLineList="quoteLineList" @fetchQLList="fetchLineList"></quote-detail>

      <el-button
        type="primary"
        size="large"
        style="margin: 10px auto;width: 100%;"
        @click.native="save">保存头信息</el-button>

    </el-form>

  </div>
</template>

<script>
  import {
    modifyQuote,
  } from '@/api/cstOrder/quote'
  import ElButton from "../../../../../node_modules/element-ui/packages/button/src/button.vue";
  import formBox from '../../../../components/formBox'
  import quoteHead from './quote_head'
  import quoteDetail from './quote_detail'

  export default {
    components: {
      ElButton,
      formBox,
      quoteHead,
      quoteDetail
    },
    name: 'createCompute',
    data() {
      return {
        quoteLineList:[],
        reqData:{
          client_type:1,
          company_id:'',
          quote_head:{
            avail_days:'',
            coin:'',
            coin_name:'',
            connect_man:'',
            cst_company_id:'',
            cst_name:'',
            email:'',
            handler:'',
            handler_name:'',
            phone:'',
            prod_name:'',
            quote_date:'',
            quote_id:'',
            quote_no:'',
            salesman:'',
            salesman_name:''
          }
        },
        //lineProductList:[],
      }
    },
    mounted() {

    },
    methods: {
      save(){
        modifyQuote(this.reqData)
          .then(res => {
            this.reqData.quote_head.quote_id = res.quote_head.quote_id
            this.reqData.quote_head.quote_no = res.quote_head.quote_no
            this.$message({
              type: 'success',
              message: '保存成功,您可以继续添加行信息'
            });
          })
          .catch(err => {
            console.log(err);
            this.$message.error('保存失败!')
          })
      },
      getQLLVal(data){
        console.log(data)
        if(data.type == 1){
          this.quoteLineList = data.data
        }else if(data.type == 2){
          this.quoteLineList.push(data.data)
        }
      },
      fetchLineList(data){
        this.quoteLineList = data
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
